package utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;

import org.apache.log4j.PropertyConfigurator;

public class Config {

	private String propsPath="/props/settings.properties";
	private final static Properties prop = new Properties();
	private InputStream in;
	
	//private static int timeBetweenFindObjectMilis;
	private static int timeWaitForElementPresentSeconds;
	private static int timeAfterExitMilis;
	
	private static int maxTryCountAction;
	private static int threadSleepBeforeTryActionMilis;

	
	private static Config conf;
	
	private Config() throws IOException
	{
		in = this.getClass().getResourceAsStream(propsPath);
		prop.load(in);
		PropertyConfigurator.configure(prop);
				
	}
	
	public static Config getInstance()
	{
		if(conf==null)
		{
			try {
				conf = new Config();
				listProps();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return conf;		
	}
	
	private static void listProps()
	{

	    Enumeration<?> e = prop.propertyNames();

	    System.out.println("USTAWIENIA:  ");
	    while (e.hasMoreElements()) {
	      String key = (String) e.nextElement();
	      System.out.println("KEY:  " + key.trim() + "  =  " + prop.getProperty(key));
/*	      if(key.equals("timeBetweenFindObjectMilis"))
	      {
	    	  timeBetweenFindObjectMilis=Integer.parseInt(prop.getProperty(key).trim());
	      } 
	      else */
	      if (key.equals("timeWaitForElementPresentSeconds")) 
	      {
	    	  timeWaitForElementPresentSeconds=Integer.parseInt(prop.getProperty(key).trim());
	      }
	      else if (key.equals("timeAfterExitMilis")) 
	      {
	    	  timeAfterExitMilis=Integer.parseInt(prop.getProperty(key).trim());
	      }
	      else if (key.equals("maxTryCountAction")) 
	      {
	    	  maxTryCountAction=Integer.parseInt(prop.getProperty(key).trim());
	      }
	      else if (key.equals("threadSleepBeforeTryActionMilis")) 
	      {
	    	  threadSleepBeforeTryActionMilis=Integer.parseInt(prop.getProperty(key).trim());
	      }
	      
	      
	      
	      
	    	  
	    }
	}

/*	public int getTimeBetweenFindObjectMilis() {
		return timeBetweenFindObjectMilis;
	}*/

	public int getTimeWaitForElementPresentSeconds() {
		return timeWaitForElementPresentSeconds;
	}

	public int getTimeAfterExitMilis() {
		return timeAfterExitMilis;
	}

	public int getMaxTryCountAction() {
		return maxTryCountAction;
	}

	public int getThreadSleepBeforeTryActionMilis() {
		return threadSleepBeforeTryActionMilis;
	}
	
	
}
